package com.javasm.service.goods.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javasm.common.page.PageResult;
import com.javasm.domin.criteria.goods.BaseBrandCriteria;
import com.javasm.domin.entity.goods.BaseBrand;
import com.javasm.mapper.goods.BaseBrandMapper;
import com.javasm.service.base.impl.BaseServiceimpl;
import com.javasm.service.goods.IBaseBrandService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whl
 * @since 2022-01-16
 */
@Service
@Transactional
@RequiredArgsConstructor
public class BaseBrandServiceImpl extends BaseServiceimpl<BaseBrand> implements IBaseBrandService {

    private final BaseBrandMapper baseBrandMapper;

    @Override
    public PageResult<BaseBrand> searchPage(BaseBrandCriteria brandCriteria) {

            PageHelper.startPage(brandCriteria.getCurrentPage(), brandCriteria.getPageSize());
            LambdaQueryWrapper<BaseBrand> lambda = new QueryWrapper<BaseBrand>().lambda();

            if (!StringUtils.isEmpty(brandCriteria.getBrandName())) {
                lambda.like(BaseBrand::getBrandName, brandCriteria.getBrandName());
            }
            List<BaseBrand> baseBrands = baseBrandMapper.selectList(lambda);
            PageInfo<BaseBrand> pageInfo = new PageInfo<>(baseBrands);

            return new PageResult<BaseBrand>(pageInfo.getTotal(), baseBrands);
    }
}
